<script>
import {listAnimation}  from '@/api/type/animation'
import UniCard from "@/uni_modules/uni-card/components/uni-card/uni-card.vue";

export default {
  components: {UniCard},
  data() {
    return {
      list: [],
      weekdays : {
        1: "周一",
        2: "周二",
        3: "周三",
        4: "周四",
        5: "周五",
        6: "周六",
        7: "周日"
      },
      dict:{},
    }
  },
  methods:{
    getList(){
      listAnimation([]).then(res => {
        this.list = res.rows
        // console.log(this.list)
      })
    },
    // 将 JSON 字符串转换为 JSON 对象
    jsonParse(jsonString) {
      try {
        return JSON.parse(jsonString);
      } catch (error) {
        // console.error("Failed to parse JSON:", error);
        return [{}];
      }
    },
    openUrl(url) {
      if (url) {
        window.open(url, '_blank');
      }
    },
    getDict(){

    },

},
  onLoad() {

  },mounted() {
    this.getList()
    this.getDict()
  }
}
</script>

<template>
<view>
  <button @click="getList" v-if="list.length === 0">获取数据</button>
  <button @click="getList" v-else>更新数据</button>
<!--{{list}}-->
<!--  <view  v-for="(item,index) in list" :key="index" class="item" >-->
<!--    {{item}}-->

<!--  </view>-->
  <uni-card v-for="(item,index) in list" :key="index" :title="item.season !==null || item.season !==0 ? item.name2 + '-第' + item.season + '季' : item.name2" :extra="item.name1" :is-full="false">
<!--   {{item}}-->
<!--    <view>{{item.season}}</view>-->
    <image :src="item.pictureUrl" style="display: block;text-align: center;margin:0 auto;width: 100%;height: 50vh"/>
    <view v-if="item.have >0 " style="text-align: center">有{{item.have}}集<br/></view>
    <view v-if="item.renew !==null && item.renew !=='[]' && item.renew.length !==4" style="text-align: center">
      <p v-for="(time, index) in jsonParse(item.renew)" :key="index" style="text-align: center">
        {{ weekdays[time.day] }} &nbsp; {{ time.clock }} <br/>
      </p>
    </view>
    <view v-if="item.url !==null && item.url !=='[{}]' && item.url.length !==4" style="text-align: center">
<!--      {{ item.url }}-->
      <button v-for="(url, index) in jsonParse(item.url)" :key="index" @click="openUrl(url.url)">
        {{ url.name }}
      </button>
    </view>


  </uni-card>
</view>
</template>

<style>

</style>